#!/usr/bin/env bash

# ----------------------------------------------------------------------
# Filename:   03-ssh-run.sh
# Version:    1.0
# Date:       2020/04/24
# Author:     Lz
# Email:      lz843723683@163.com
# History：     
#             Version 1.0, 2020/04/24
# Function:   ssh - 禁止root使用ssh登录
# Out:        
#              0 => TPASS
#              1 => TFAIL
#              other=> TCONF
# ----------------------------------------------------------------------

## TODO : 测试收尾清除工作
#
sshClean_FTGW_RUN(){
	return $TPASS
}


## TODO: 调用程序退出函数
#    In: $1 => 调用脚本结果值
sshExit_FTGW_RUN(){
        # 调用退出函数，其中调用了clean相关函数
	Exit_FTLIB ${1}
}


## TODO: 用户界面
#
sshUSAGE_FTGW_RUN(){
	USAGE_FTLIB "金风服务器运行版 - 禁止root远程登录(ssh)"
}


## TODO : 测试前的初始化 
#  Out  : 
#         0 => TPASS
#         1 => TFAIL
#         other=> TCONF
sshInit_FTGW_RUN(){
        # 调用初始化函数
	Init_FTLIB "sshClean_FTGW_RUN"
        # 调用用户界面函数
 	sshUSAGE_FTGW_RUN
}


## TODO ：判断配置文件中是否存在指定字段
#
sshTest01_FTGW_RUN(){
	local cfgfile="/etc/ssh/sshd_config"
	local field="PermitRootLogin"
	local flag="no"

	# 判断配置文件
	echo 'cat' "${cfgfile}"
	cat ${cfgfile} | grep "${field}"
	cat ${cfgfile} | grep "^${field}" | grep -i -q ${flag}
        RetParse_FTLIB "${cfgfile} 默认配置为 ${field} ${flag} " "False"
}


## TODO : Main
#  Out  : 
#         0 => TPASS
#         1 => TFAIL
#         other => TCONF
sshMain_FTGW_RUN(){
	sshInit_FTGW_RUN

	sshTest01_FTGW_RUN

	return ${TPASS}	
}

sshMain_FTGW_RUN
sshExit_FTGW_RUN $?
